<template>
	<view>
		<view class="mt100 pd jhbbnjsert " :class="isdfff?'':'act'"  v-if="isdfff">			
			<navigator class="kjeert" :class="sd.cls" :key="idx" v-for="(sd,idx) in jhhbnjsd" @tap="jjnsdrt(sd)">
				{{sd.name}}
				<icon v-if="sd.cls" type="success" color="#fff" size="18" class="jjhnxeett"></icon>
			</navigator>			
		</view>
		<view class="mt100 pd jhbbnjsert " :class="isdfff?'':'act'"  v-else>			
			<navigator :url="'GroupPermissionDetails?carid='+carid+'&gid='+sd.id" class="kjeert"  :key="idx" v-for="(sd,idx) in jhhbnjsd" >
				{{sd.name}}
				<!-- <icon v-if="sd.cls" type="success" color="#fff" size="18" class="jjhnxeett"></icon> -->
			</navigator>
		</view>
		<view class="pd" v-if="!isdfff">
			<navigator  :url="'ShareTo?carid='+carid" class="mt40 sdfsdtuyye fz36 cen">
				共享到
			</navigator>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isdfff:false,
				jhhbnjsd:[
					
				],
				carid:""
			}
		},
		components: {},
		onNavigationBarButtonTap() {
			let textsd = '',
			th=this
			if(!this.isdfff){
				this.isdfff = true
				textsd = '取消授权'
				this.setStyle(0, textsd);
			} else {
				let names=""
				th.jhhbnjsd.map((b)=>{
					if(b.cls){
						names+=b.name+'、'
					}
				})
				if (names.length > 0) {
				    names = names.substr(0, names.length - 1);
				}
				let ids=""
				th.jhhbnjsd.map((b)=>{
					if(b.cls){
						ids+=b.id+'、'
					}
				})
				if (ids.length > 0) {
				    ids = ids.substr(0, ids.length - 1);
				}
				th.jhhbnjsd.map((q)=>{
					if(q.cls){
						uni.showModal({
							title:'',
							content:'您确定要取消该车辆对'+names+'的授权吗？',
							success(e) {
								if(e.confirm){
									th.isdfff = false
									textsd = '批量授权'
									th.setStyle(0, textsd);
									th.del(ids)
									uni.navigateBack({
										delta:1
									})
								}
							}
						})
					}else{
						uni.showToast({
							icon:"none",
							title:'请选择群组'
						})
					}
				})
				
			}
			
		},
		onLoad(options) {		
			this.carid=options.carid
			this.lists(this.carid)
			console.log("得到的id",options.carid)
		},	
		onShow() {
			this.lists(this.carid)
		},
		methods: {
			setStyle(index, text) {
				let pages = getCurrentPages();
				let page = pages[pages.length - 1];
				// #ifdef APP-PLUS
				let currentWebview = page.$getAppWebview();
				let titleNView = currentWebview.getStyle().titleNView;
				// 添加文字过长截取为3个字符，请根据自己业务需求更改
				titleNView.buttons[0].text = text;
				currentWebview.setStyle({
					titleNView: titleNView
				});
				// #endif
				// #ifdef H5
				// h5 临时方案
				document.getElementsByClassName('uni-btn-icon')[1].innerText = text;
				// #endif
			},
			async del(ids){
				var that=this
				let params={}
				params.ids=ids
				params.cid=this.carid
				let dels=await this.get('/api/car/cancel_authorization',params,'DELETE')
				console.log("取消",dels)
				if(dels.code==0){
					uni.showToast({
						title:'取消成功'
					})
					that.lists(that.carid)
				}
			},
			jjnsdrt(e){
				if(!this.isdfff){
					return
				}
				if(e.cls){
					e.cls=''
				}else{
					e.cls="act"
				}
			},
			async lists(id){
				let adlist=await this.get('/api/car/'+id+'/authorized_list')				
				adlist.data.map((a)=>{
					a.cls=""					
				})
				console.log("授权列表",adlist.data)
				this.jhhbnjsd=adlist.data
				
			}
		},
		mounted() {}
	}
</script>
<style scoped>
	.kjeert {
		position: relative;
	}

	.kjeert.act {
		background: transparent;
		border-color: #fff;
	}
	.jjhnxeett{
		position: absolute;
		right: 0upx;
		top: -30upx;
	}
	.jhbbnjsert.act .kjeert{
		background:#353C51 !important;
		border-color: #353C51 !important;
	}
	.jhbbnjsert.act .jjhnxeett{
		display: none;
		
	}
	.jhbbnjsert{
		min-height: 800upx;
	}
	.sdfsdtuyye{
		height:100upx;
		line-height: 100upx;
		color: #fff;
		background:linear-gradient(180deg,rgba(27,213,185,1) 0%,rgba(22,137,213,1) 100%);
		border-radius:12upx;
	}
</style>
